package com.ruoyi.system.utils;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.system.domain.GzdsQuestionInfo;

/**
 * @author sxctc
 * @title: QuestionUtils
 * @projectName ruoyi
 * @description: 试题工具类
 * @date 2021/5/31 15:59
 */
public class QuestionUtils {

    /**
     * 设置试题缓存
     *
     * @param key 参数键
     * @param questionInfo 试题
     */
    public static void setQuestionCache(String key, GzdsQuestionInfo questionInfo)
    {
        SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), questionInfo);
    }

    /**
     * 获取试题缓存
     *
     * @param key 参数键
     * @return question 试题
     */
    public static GzdsQuestionInfo getQuestionCache(String key)
    {
        Object cacheObj = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
        if (StringUtils.isNotNull(cacheObj))
        {
            GzdsQuestionInfo question = StringUtils.cast(cacheObj);
            return question;
        }
        return null;
    }

    /**
     * 设置cache key
     *
     * @param configKey 参数键
     * @return 缓存键key
     */
    public static String getCacheKey(String configKey)
    {
        return Constants.SYS_DICT_KEY + configKey;
    }
}
